log using "$Rep_smokelabor/2_analysis/output_logs/table1.log", replace 

	use "$Rep_smokelabor/1_build/regdata/county_quarter.dta", clear 

	local tbl_settings_log format(%6.3f) parentheses(stderr) asterisk()
	local tbl_settings_pmil format(%6.1f) parentheses(stderr) asterisk()
	
	** panel a
	if 1 {
		
		* pm2.5
		reghdfe pm25 hms_deep [aw=seer_pop], a(fe_countyqtroy fe_styr) vce(cluster countyfip fe_stqtros)
		summ pm25 [aw=seer_pop] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_a.dta", addlabel(outcome_mean, "`ymean'") table(pm25, `tbl_settings_log') replace
		
		* income 
		reghdfe d_pc_qwi_payroll hms_deep [aw=seer_pop], a(fe_countyqtroy fe_styr) vce(cluster countyfip fe_stqtros)
		summ pc_qwi_payroll [aw=seer_pop] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_a.dta", addlabel(outcome_mean, "`ymean'") table(earnings, `tbl_settings_log') append
		
		* emp 
		reghdfe d_pmil_qwi_emptotal hms_deep [aw=seer_pop16plus], a(fe_countyqtroy fe_styr) vce(cluster countyfip fe_stqtros)
		summ pmil_qwi_emptotal [aw=seer_pop16plus] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_a.dta", addlabel(outcome_mean, "`ymean'") table(employment, `tbl_settings_pmil') append
		
		* lfp
		reghdfe d_pmil_lau_lfp hms_deep [aw=seer_pop] , a(fe_countyqtroy fe_styr) vce(cluster countyfip fe_stqtros)
		summ pmil_lau_lfp [aw=seer_pop] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_a.dta", addlabel(outcome_mean, "`ymean'") table(lfp, `tbl_settings_pmil') append
		
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/table1_a.dta", clear
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			replace var="observations" if var=="N"
			ingap 3
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/table1_a.dta", replace
		restore 
	}
	
	** panel b
	if 1 {
	
		* income 
		reghdfe d_pc_qwi_payroll pm25  [aw=seer_pop], a(fe_countyqtroy fe_styr) vce(cluster countyfip fe_stqtros)
		summ pc_qwi_payroll [aw=seer_pop] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_b.dta", addlabel(outcome_mean, "`ymean'") table(earnings, `tbl_settings_log') replace
		
		* emp 
		reghdfe d_pmil_qwi_emptotal pm25 [aw=seer_pop16plus] , a(fe_countyqtroy fe_styr) vce(cluster countyfip fe_stqtros)
		summ pmil_qwi_emptotal [aw=seer_pop16plus] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_b.dta", addlabel(outcome_mean, "`ymean'") table(employment, `tbl_settings_pmil') append
		
		* lfp  
		reghdfe d_pmil_lau_lfp pm25 [aw=seer_pop] , a(fe_countyqtroy fe_styr) vce(cluster countyfip fe_stqtros)
		summ pmil_lau_lfp [aw=seer_pop] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_b.dta", addlabel(outcome_mean, "`ymean'") table(lfp, `tbl_settings_pmil') append
	
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/table1_b.dta", clear
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			replace var="observations" if var=="N"
			ingap 3
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/table1_b.dta", replace
		restore
}
	
	** panel c
	if 1 {
		
		* income
		ivreghdfe d_pc_qwi_payroll (pm25=hms_deep) [aw=seer_pop] , a(fe_countyqtroy fe_styr) cluster(countyfip fe_stqtros)
		summ pc_qwi_payroll [aw=seer_pop] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_c.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(earnings, `tbl_settings_pmil') replace
		
		* emp
		ivreghdfe d_pmil_qwi_emptotal (pm25=hms_deep)  [aw=seer_pop16plus] , a(fe_countyqtroy fe_styr) cluster(countyfip fe_stqtros)
		summ pmil_qwi_emptotal [aw=seer_pop16plus] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_c.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(employment, `tbl_settings_pmil') append
		
		* lfp
		ivreghdfe d_pmil_lau_lfp (pm25=hms_deep) [aw=seer_pop] , a(fe_countyqtroy fe_styr) cluster(countyfip fe_stqtros)
		summ pmil_lau_lfp [aw=seer_pop] if e(sample)
		local ymean=`r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/table1_c.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(lfp, `tbl_settings_pmil') append
		
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/table1_c.dta", clear
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			replace var="observations" if var=="N"
			ingap 3
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/table1_c.dta", replace
		restore
	
	}
	
log close